const path = require('path')
function resolve (dir) {
  return path.join(__dirname, dir)
}
// let userInfo
// if (process.env.NODE_ENV === 'production') {
//   userInfo = '<%-JSON.stringify(userInfo)%>'
// } else {
//   userInfo = JSON.stringify([1, 2, 4])
// }

// console.log(process.env)
if(process.env.NODE_ENV === 'production') {
  process.env.VUE_APP_client_id = '<%- client_id %>'
  process.env.VUE_APP_redirect_uri = '<%- redirect_uri %>'
  process.env.VUE_APP_url = '<%- url %>'
} else {
  client_id ='aa'
  redirect_uri = '/asda'
  url = '/bbb'
}

var pages = {
  background: {
    entry: 'src/projects/background/main.js',
    template: 'public/background.html',
    filename: 'background.html',
    // userInfo: userInfo,
    title: 'zeeephr服务器管理后台界面',
    chunks: ['chunk-vendors', 'chunk-common', 'background']
  },
  applyClient: {
    entry: 'src/projects/applyClient/main.js',
    template: 'public/applyclient.html',
    filename: 'applyClient.html',
    // userInfo: userInfo,
    title: '申请应用',
    chunks: ['chunk-vendors', 'chunk-common', 'applyClient']
  },
  authorize: {
    entry: 'src/projects/authorize/main.js',
    template: 'public/authorize.html',
    filename: 'authorize.html',
    // userInfo: userInfo,
    title: '统一登录界面',
    chunks: ['chunk-vendors', 'chunk-common', 'authorize'],
  },
}
module.exports = {
  outputDir: 'dist',
  assetsDir: 'static',
  // publicPath: process.env.NODE_ENV === 'production'
  //   ? '/dist/'
  //   : '/',
  productionSourceMap: false,
  pages,
  devServer: {
    proxy: {
      '/': { target: 'http://127.0.0.1:9100' },
      '/managerapi': { target: 'http://127.0.0.1:9100' },
      '/userapi': { target: 'http://127.0.0.1:9100' },
      '/captcha/get': { target: 'http://10.108.11.46' }
    }
  },
  chainWebpack: (config) => {
    // 修改文件引入自定义路径
    config.resolve.alias
      .set('@', resolve('src'))
      // .set('store', resolve('src/store'))
      // .set('plugins', resolve('src/plugins'))
      // .set('style', resolve('src/assets/css'))
      // .set('script', resolve('src/assets/scripts'))
    // Object.keys(pages).forEach(entryName => {
    //   config.plugins.delete(`prefetch-${entryName}`)
    // })
  },
  pluginOptions: {
    foo: {
      userInfo: 123456
    }
  },
  // plugins: [
  //   new HtmlWebpackPlugin({
  //     template: 'public/index.html',
  //     filename: 'admin.html',
  //     userInfo: 123456
  //   })
  // ]
}
